import {Component, OnInit} from "@angular/core";
import {Page} from "../../../public/util/page";
import {JlbService} from "../jlb.service";
import {Enums, States} from '../../../public/setting/enums';
import {SettingUrl} from "../../../public/setting/setting_url";
import {Util} from '../../../public/util/util';

@Component({
  selector: 'app-jlb-ore-log-list',
  templateUrl: './jlb-ore-log-list.component.html',
  styleUrls: ['./jlb-ore-log-list.component.scss']
})
export class JlbOreLogListComponent implements OnInit {
  public searchParams: any = {};//搜索参数
  public jlbOreLogList: Page = new Page(); //供应商
  public _loading: boolean = false;
  public routerLinks = SettingUrl.ROUTERLINK;//路由
  public jlbOreLogType = Enums.jlbOreLogType;
  public JlbOreLogEvent = Enums.jlbOreLogEvent;
  public states = States;       // 状态

  constructor(private jlbService: JlbService) {
  }

  ngOnInit() {
    this.queryJlbOreLogList()
  }

  /**
   * 查询jlbOreLog列表
   * @param curPage 当前页
   */
  queryJlbOreLogList(curPage?: number) {
    this._loading = true;
    if (curPage) this.jlbOreLogList.curPage = curPage;//当有页码时，查询该页数据
    this.jlbOreLogList.params = {
      createTimeBegin:this.searchParams.createTimeBegin,
      createTimeEnd:this.searchParams.createTimeEnd,
      account:this.searchParams.account,
      curPage: this.jlbOreLogList.curPage, //目标页码
      pageSize: this.jlbOreLogList.pageSize, //每页条数
    };
    this.jlbService.getJlbOreLogList(this.jlbOreLogList.params).then((res: Page) => {
      this._loading = false;
      this.jlbOreLogList = res;
    }).catch(err => {
      this._loading = false;
    })
  }

  dateChange(date){
    if(date && date.length === 2){
      this.searchParams.createTimeBegin = Util.formateGBdate(date[0]);
      this.searchParams.createTimeEnd = Util.formateGBdate(date[1]);
    }else{
      this.searchParams.createTimeBegin = null;
      this.searchParams.createTimeEnd = null;
    }
  }

  /**
   * 重置搜索
   */
  resetSearch() {
    this.searchParams = {};
    this.queryJlbOreLogList(1)
  }
}
